import Vue from 'vue'
import VueRouter from 'vue-router'
//引入注册页
import Reg from '@/views/Reg/Reg.vue'
//引入登录页
import Login from '@/views/Login/Login.vue'
//
// 导入主页
import Main from '@/views/Main/Main.vue'
//以下都是 主页面的二级路由
//导入首页组件
import Home from '@/views/Menus/Home/Home.vue'
import UserInfo from '@/views/Menus/User/Userinfo.vue'
import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
import UserPwd from '@/views/Menus/User/UserPwd.vue'

Vue.use(VueRouter)
const routerPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return routerPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/reg',
    name: 'reg',
    component: Reg
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/',
    name: 'main',
    component: Main,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: Home
      },
      {
        path: 'user-info',
        name: 'userInfo',
        component: UserInfo
      },
      {
        path: 'user-avatar',
        name: 'userAvatar',
        component: UserAvatar
      },
      //重置密码
      {
        path: 'user-pwd',
        name: 'userPwd',
        component: UserPwd
      }
    ]
  }
]

const router = new VueRouter({
  routes
})

export default router
